<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "base_sys_preview".
 *
 * @property integer $id
 * @property integer $item_id
 * @property integer $fid
 * @property integer $mid
 * @property integer $img_small_id
 * @property integer $img_thumb_id
 * @property integer $img_url_id
 * @property integer $img_tz_id
 * @property string $coating
 */
class BaseSysPreview extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'base_sys_preview';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['item_id', 'fid', 'mid', 'img_small_id', 'img_thumb_id', 'img_url_id', 'img_tz_id'], 'integer'],
            [['coating'], 'string', 'max' => 100],
            [['fid', 'mid', 'item_id'], 'unique', 'targetAttribute' => ['fid', 'mid', 'item_id'], 'message' => 'The combination of Item ID, Fid and Mid has already been taken.']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'item_id' => 'Item ID',
            'fid' => 'Fid',
            'mid' => 'Mid',
            'img_small_id' => 'Img Small ID',
            'img_thumb_id' => 'Img Thumb ID',
            'img_url_id' => 'Img Url ID',
            'img_tz_id' => 'Img Tz ID',
            'coating' => 'Coating',
        ];
    }
    public function getFabric()
    {
        return $this->hasOne(Fabric::className(), ['id'=>'fid']);
    }
    public function getMaterial()
    {
        return $this->hasOne(Material::className(), ['id'=>'mid']);
    }
    public function getMainImageL()
    {
        return $this->hasOne(Image::className(), ['id'=>'img_url_id'])->from(['preview_main_img_l'=>Image::tableName()]);
    }
    public function getMainImageM()
    {
        return $this->hasOne(Image::className(), ['id'=>'img_thumb_id'])->from(['preview_main_img_m'=>Image::tableName()]);
    }
    public function getMainImageS()
    {
        return $this->hasOne(Image::className(), ['id'=>'img_small_id'])->from(['preview_main_img_s'=>Image::tableName()]);
    }
    public function getTzImage()
    {
        return $this->hasOne(Image::className(), ['id'=>'img_tz_id'])->from(['preview_tz_img'=>Image::tableName()]);
    }
}
